package com.zzq.my.jetpacks.jectpackapp.ui.fragment


import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseFragment
import com.zzq.my.jetpacks.jectpackapp.*
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.databinding.FragmentBBinding
import com.zzq.my.jetpacks.jectpackapp.generate123Fragments
import com.zzq.my.jetpacks.util.loadFragments
import com.zzq.my.jetpacks.util.showHideFragment

/**
 * 描述：class describe
 * 作者：zhuangzeqin
 * 时间: 2021/12/24-16:36
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class BFragment : BaseFragment(R.layout.fragment_b), View.OnClickListener {
    private val binding by viewBinding(FragmentBBinding::bind)
    private lateinit var fragmentsMap: Map<String, Fragment>

    companion object {
        fun newInstance() = BFragment()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.btn1.setOnClickListener(this)
        binding.btn2.setOnClickListener(this)
        binding.btn3.setOnClickListener(this)
    }

    override fun lazyInit() {
        fragmentsMap = generate123Fragments()
        loadFragments(R.id.fl_b_container,0,*fragmentsMap.values.toTypedArray())
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.btn_1 -> {
                showHideFragment(fragmentsMap.getValue(FRAGMENT_ONE))
            }
            R.id.btn_2 -> {
                showHideFragment(fragmentsMap.getValue(FRAGMENT_TWO))
            }
            R.id.btn_3 -> {
                showHideFragment(fragmentsMap.getValue(FRAGMENT_THREE))
            }
        }
    }
}